package com.webchat.pgc.controller.sys;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.sys.SysDataDictionaryDetailRequestVo;
import com.webchat.domain.vo.request.sys.SysDataDictionaryRequestVO;
import com.webchat.domain.vo.response.sys.SysDataDictionaryBaseVO;
import com.webchat.domain.vo.response.sys.SysDataDictionaryDetailBaseVO;
import com.webchat.domain.vo.response.sys.SysDataDictionaryResponseVO;
import com.webchat.pgc.service.sys.SysDataDictionaryDetailService;
import com.webchat.pgc.service.sys.SysDataDictionaryService;
import com.webchat.rmi.pgc.sys.SysDataDictionaryClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 数据字典 控制器
 *
 * @author SongRenShuo
 * @date 2025/06/25
 */
@RestController
public class SysDataDictionaryController implements SysDataDictionaryClient {


    @Autowired
    private SysDataDictionaryService sysDataDictionaryService;
    @Autowired
    private SysDataDictionaryDetailService sysDataDictionaryDetailService;

    /**
     * 获取数据字典详情列表
     *
     * @param code 数据字典编号
     * @return {@link APIResponseBean }<{@link Map }<{@link String },{@link String }>>
     */
    @Override
    public APIResponseBean<Map<String, String>> detail(@PathVariable String code) {
        SysDataDictionaryBaseVO dataDictionaryBaseVO = sysDataDictionaryService.baseDetail(code);
        Map<String, String> vos = sysDataDictionaryDetailService.detail(dataDictionaryBaseVO);
        return APIResponseBeanUtil.success(vos);
    }


    /**
     * 创建或者更新数据字典
     *
     * @param requestVO 请求 VO
     * @return {@link APIResponseBean }<{@link Long }>
     */
    @Override
    public APIResponseBean<Long> save(@RequestBody SysDataDictionaryRequestVO requestVO) {
        Long dictionaryId = sysDataDictionaryService.save(requestVO);
        return APIResponseBeanUtil.success(dictionaryId);
    }

    /**
     * 删除数据数据字典
     *
     * @param dictionaryId 主键
     * @param userId       用户 ID
     * @return {@link APIResponseBean }<{@link Boolean }>
     */
    @Override
    public APIResponseBean<Boolean> delete(@PathVariable Long dictionaryId, @PathVariable String userId) {
        boolean res = sysDataDictionaryService.delete(dictionaryId, userId);
        return APIResponseBeanUtil.success(res);
    }

    /**
     * 分页查询数据字典
     *
     * @param categoryId     分类 ID
     * @param code     编号
     * @param name     名称
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @return {@link APIPageResponseBean }<{@link SysDataDictionaryResponseVO }>
     */
    @Override
    public APIPageResponseBean<SysDataDictionaryResponseVO> page(Long categoryId, String code, String name, Integer pageNo, Integer pageSize) {

        return sysDataDictionaryService.page(categoryId, code, name, pageNo, pageSize);
    }


    /**
     * 创建或者更新数据字典详情
     *
     * @param requestVO 请求 VO
     * @return {@link APIResponseBean }<{@link Long }>
     */
    @Override
    public APIResponseBean<Long> saveDetail(@RequestBody SysDataDictionaryDetailRequestVo requestVO) {
        Long categoryId = sysDataDictionaryDetailService.save(requestVO);
        return APIResponseBeanUtil.success(categoryId);
    }

    /**
     * 删除数据字典详情
     *
     * @param detailId 数据字典详情主键
     * @param userId   用户 ID
     * @return {@link APIResponseBean }<{@link Boolean }>
     */
    @Override
    public APIResponseBean<Boolean> deleteDetail(@PathVariable Long detailId, String userId) {
        boolean res = sysDataDictionaryDetailService.delete(detailId, userId);
        return APIResponseBeanUtil.success(res);
    }

    /**
     * 分页查询数据字典详情
     *
     * @param dataDictionaryId     数据字典ID
     * @param code             编号
     * @param name             名称
     * @param pageNo           页码
     * @param pageSize         每页条数
     * @return {@link APIPageResponseBean }<{@link SysDataDictionaryDetailBaseVO }>
     */
    @Override
    public APIPageResponseBean<SysDataDictionaryDetailBaseVO> pageDetail(Long dataDictionaryId, String code, String name, Integer pageNo, Integer pageSize) {

        return sysDataDictionaryDetailService.page(dataDictionaryId, code, name, pageNo, pageSize);
    }
}
